package excel.imports;

import java.io.FileInputStream;

import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

import com.alibaba.fastjson.JSON;
import com.mvc.core.utils.excel.ExcelUtils;
import com.mvc.core.utils.excel.ImportRspInfo;
import com.mvc.core.utils.excel.ParseSheetCallback;

import excel.export.ProjectEvaluate;



public class MainClass {

	public static void main(String[] args) throws Exception {
		parseSheet();
		// parseSheetWithCallback();
	}

	/**
	 * 解析excel
	 * 
	 * @throws Exception
	 */
	public static void parseSheet() throws Exception {
		Workbook wb = WorkbookFactory.create(new FileInputStream("src/test/java/example/imp/import.xlsx"));
		Sheet sheet = wb.getSheetAt(0);
		// parseSheet
		ImportRspInfo<ProjectEvaluate> list = ExcelUtils.parseSheet(ProjectEvaluate.class, EvaluateVerifyBuilder.getInstance(), sheet, 3, 2);
		System.out.println(JSON.toJSONString(list));
	}

	/**
	 * 解析excel带回调函数：做一些额外字段填充
	 * 
	 * @throws Exception
	 */
	public static void parseSheetWithCallback() throws Exception {
		Workbook wb = WorkbookFactory.create(new FileInputStream("src/test/java/example/imp/import.xlsx"));
		Sheet sheet = wb.getSheetAt(0);
		// parseSheet
		ImportRspInfo<ProjectEvaluate> list = ExcelUtils.parseSheet(ProjectEvaluate.class, EvaluateVerifyBuilder.getInstance(), sheet, 3, 2, new ParseSheetCallback<ProjectEvaluate>() {
			@Override
			public void callback(ProjectEvaluate t, int rowNum) throws Exception {
				System.out.println(rowNum);
			}
		});
		System.out.println(JSON.toJSONString(list));
	}
}
